//package com.majun.config.filter5;
//
//import org.apache.commons.io.IOUtils;
//
//import javax.servlet.ReadListener;
//import javax.servlet.ServletInputStream;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletRequestWrapper;
//import java.io.BufferedReader;
//import java.io.ByteArrayInputStream;
//import java.io.IOException;
//import java.io.InputStreamReader;
//
//public class ContentCachingRequestWrapper extends HttpServletRequestWrapper {
//
//    private byte[] body;
//
//    private BufferedReader reader;
//
//    private ServletInputStream inputStream;
//
//    public ContentCachingRequestWrapper(HttpServletRequest request) throws IOException {
//        super(request);
//        //读一次 然后缓存起来
//        body = IOUtils.toByteArray(request.getInputStream());
//        inputStream = new RequestCachingInputStream(body);
//    }
//
//    public byte[] getBody() {
//        return body;
//    }
//
//    @Override
//    public ServletInputStream getInputStream() throws IOException {
//        if (inputStream != null) {
//            return inputStream;
//        }
//        return super.getInputStream();
//    }
//
//    @Override
//    public BufferedReader getReader() throws IOException {
//        if (reader == null) {
//            reader = new BufferedReader(new InputStreamReader(inputStream, getCharacterEncoding()));
//        }
//        return reader;
//    }
//
//    //代理一下ServletInputStream 里面真是内容为当前缓存的bytes
//    private static class RequestCachingInputStream extends ServletInputStream {
//
//        private final ByteArrayInputStream inputStream;
//
//        public RequestCachingInputStream(byte[] bytes) {
//            inputStream = new ByteArrayInputStream(bytes);
//        }
//        @Override
//        public int read() throws IOException {
//            return inputStream.read();
//        }
//
//        @Override
//        public boolean isFinished() {
//            return inputStream.available() == 0;
//        }
//
//        @Override
//        public boolean isReady() {
//            return true;
//        }
//
//        @Override
//        public void setReadListener(ReadListener readlistener) {
//        }
//
//    }
//
//}